<?php
/**
 * True Gallery Default layout
 *
 * @version 2.5
 * @author Alexey N. Brin (userxp@joomlaportal.ru)
 * @homepage http://truegallery.ru 
 * @filename default.php
 * @package True Gallery
 * @copyright (C) 2008-2009 by joomlatune.ru
 * @license GNU/GPL: http://www.gnu.org/copyleft/gpl.html
 * 
 * THIS GALLERY is an EVOLUTION of AkoGallery -> PonyGallery -> DatsoGallery
 *
 * If you fork this to create your own project, 
 * please make a reference to True Gallery someplace in your code 
 * and provide a link to http://www.joomlatune.ru
 *
 **/

defined('_VALID_MOS') or defined('_JEXEC') or die('Direct Access to this location is not allowed.');

// preserving outout from AJAX
if( !TG_AJAX )
{
	$task	= trim( getUrlParam('task', 'default') );
	$view	= trim( getUrlParam('view', 'category') );
	
	if( JTuneConfig::is_admin() ) {
		// ADMINISTRATOR HEADER
		appendStyle( 'admin' );
		
		if( JOOMLA_JVERSION=='1.0' ) {
			appendScript( 'mootools_1.1_pack' );
		}
		
		appendScript( 'jquery-1.3.2.pack' );
		appendScript( 'tgjshelper' );
		appendScript( 'jquery.easing.1.3.pack' );
		appendScript( 'jquery.bgiframe.pack' );
		appendScript( 'jquery.tooltip.pack' );
		appendScript( 'jquery.form-2.36.pack' );
		//appendScript( 'jquery.form' ); // shit! I forgot was there any error in ajaxForm packed file or not!
		
		include_once JTuneLayout::getFile('admin.menunav');
		//echo '<!--div id="temp" style="display:none"></div><div id="tgadmincontainer"></div-->';
	} else {
		// SITE HEADER
		
		// getting global parameters
		extract( JTuneConfig::getParameters() );
		
		if( JOOMLA_JVERSION=='1.0' ) {
			//appendScript( 'mootools_1.1_pack' ); // this could be needed in Joomla 1.0.x
		}
		
		$app	= &JTuneConfig::getApplication();
		
		if( TG_PACK && !JTuneConfig::debug() ) {
			function zipJS($type='css') {
				$text = '';
				$serial = '';
				if( $type=='css' ) {
					$files = array( 
						//'thickbox',
						'highslide',
						'skin',
						//'jquery.jcarousel',
						//'toggle',
						'true'
					);
				} else if( $type=='js' ) {
					$files = array(
						'jquery-1.3.2.pack',
						//'jquery.history.pack',
						'tgjshelper',
						'jquery.easing.1.3.pack',
						'jquery.bgiframe.pack',
						//'jquery.tooltip.pack',
						//'thickboxa',
						//'toggle_pack',
						//'jcarousellite.pack'
					);
				}
				
				if( $files ) {
					foreach( $files as $file ) {
						$text .= JTuneLayout::getLayoutFileContent($file, $type, '.'.$type )."\n";
					}
				}
				return $text;
			}
			
			$cache = & JTuneCache::getCache( TG_CMP );
			$cache->setCaching(1);
			$callback	= 'zipJS';
			
			$args	= 'css';
			$id		= $cache->_makeId( $callback, $args );
			$buffer	= $cache->get( $callback, $args, $id );
			$path	= $cache->_handler->_getFilePath( $id, TG_CMP );
			$index	= basename($path, '.php');
			
			$cachefile = JTuneLayout::getLayoutFile( 'assets','','.php',false,null);
			
			$app->addCustomHeadTag( getCSS($cachefile.='?t=css&h='.$index) );
			
			$args	= 'js';
			$id		= $cache->_makeId( $callback, $args );
			$buffer	= $cache->get( $callback, $args, $id );
			$path	= $cache->_handler->_getFilePath( $id, TG_CMP );
			$index	= basename($path, '.php');
			
			$app->addCustomHeadTag( getJS($cachefile.='?t=css&h='.$index) );
			
		} else {
			
			$cssfiles = array(
				//'thickbox',
				'highslide',
				'skin',
				//'jquery.jcarousel',
				//'toggle',
				'true'
			);
			foreach( $cssfiles as $file ) {
				appendStyle($file);
			}
			
			$jsfiles = array(
				'jquery-1.3.2.pack',
				'tgjshelper',
				'jquery.easing.1.3.pack',
				//'jquery.bgiframe.pack',
				//'jquery.tooltip.pack',
				//'thickboxa',
				//'toggle_pack',
				//'jcarousellite.pack'
				//'jquery.history.pack',
			);
			
			foreach( $jsfiles as $file ) {
				appendScript($file);
			}
		}
		
		$app->setPageTitle( JText::_('TG_GALLERY') );
	}
}
?>